package com.swathi.test.dao.Impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.swathi.test.dao.UserDao;
import com.swathi.test.vo.User;

@Component
public class UserDaoImpl implements UserDao {

	private HibernateTemplate template ;
	
	private Session session;
	
	/**
	 * To intantiate Hibernate Template, we are doing a dependency injection.
	 * @param sessionFactory
	 */
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		  this.template = new HibernateTemplate(sessionFactory);
		  this.session = this.template.getSessionFactory().openSession();
		 }
	@Override
	public List<User> getUsers() {
		//List<User> users =  template.find("from User");
		List<User> users =  session.createCriteria(User.class).list();
		return users;
	}
	
}
